package com.group02.community.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.group02.community.entity.interaction.Interaction;
import com.group02.community.entity.interaction.ZyComment;
import com.group02.community.entity.interaction.ZyCommunityInteraction;

import com.group02.community.entity.vo.CommentVO;
import com.group02.community.entity.vo.InteractionVO;
import com.group02.community.mapper.InteractionMapper;
import com.group02.community.service.InteractionService;
import com.group02.community.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class InteractionServiceImpl extends ServiceImpl<InteractionMapper, ZyCommunityInteraction> implements InteractionService {

    @Autowired
    private InteractionMapper interactionMapper;

    @Override
    public IPage<InteractionVO> getAllInteraction(Long current, Long size, Interaction interaction) {
        InteractionVO interactionVO = new InteractionVO();
        interactionVO.setOwnerNickname(interaction.getOwnerNickname());
        interactionVO.setOwnerRealName(interaction.getOwnerRealName());
        interactionVO.setOwnerPhoneNumber(interaction.getOwnerPhoneNumber());
        Page<InteractionVO> interactionVOPage = new Page<>(current, size);
        interactionVOPage.setOptimizeCountSql(false);
        return interactionMapper.getAllInteraction(interactionVOPage,interactionVO);
    }

    @Override
    public List<CommentVO> getCommentByInteractionId(String id) {
        return interactionMapper.getCommentByInteractionId(id);
    }

    @Override
    public void updateCommentAndInteraction(String id) {
        interactionMapper.updateCommentByInteraction(id);
        interactionMapper.updateInteractionByInteraction(id);
    }

    @Override
    public void updateCommentByCommentId(String commentId) {
        interactionMapper.updateCommentByCommentId(commentId);
    }

    @Override
    public List<InteractionVO> getAllInteractions() {
        List<InteractionVO> allInteractions = interactionMapper.getAllInteractions();
        return allInteractions;
    }

    @Override
    public void saveComment(ZyComment zyComment) {
        zyComment.setCommentId(String.valueOf(UUIDUtils.getId()));
        zyComment.setCreateTime(LocalDateTime.now());
        zyComment.setDelFlag(0L);
        interactionMapper.saveComment(zyComment);
    }

}
